package com.hundsun.yr.universal.p2p.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

import com.hundsun.yr.universal.library.netstatus.NetUtils;
import com.hundsun.yr.universal.p2p.presenter.base.RequestPresenter;
import com.hundsun.yr.universal.p2p.ui.activity.base.BaseMineWebActivity;
import com.hundsun.yr.universal.p2p.view.base.BaseWebView;


/**
 * @version V1.0
 * @Title: WebProtocolActivity.java
 * @Description: 协议界面
 * @date 2016-3-21 下午7:28:34
 * @author:hejun.shen
 * @email:shenhj15971@hundsun.com
 * @replace author:
 * @replace date:
 */
public class WebProtocolActivity extends BaseMineWebActivity implements BaseWebView {

    /**
     * 获取数据接口
     **/
    private RequestPresenter mPresenter = null;
    /**
     * 协议枚举
     **/
//    private String mProtocolCode;
    /**
     * 协议枚举
     **/
    public static final String PROTOCOL_CODE = "PROTOCOL_CODE";
    /**
     * 协议地址
     **/
    private String mUrl;

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        // TODO Auto-generated method stub
        return true;
    }

    @Override
    protected View getLoadingTargetView() {

        return mBrowserLayout;
    }


    @Override
    protected void onNetworkConnected(NetUtils.NetType type) {
        mBrowserLayout.refresh();
        toggleHide();
    }

    @Override
    protected void getBundleExtras(Bundle extras) {
        super.getBundleExtras(extras);
//        mProtocolCode = extras.getString(PROTOCOL_CODE);
    }

    @Override
    protected void onNetworkDisConnected() {
        toggleNetworkError(true, new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                if (NetUtils.isNetworkConnected(getBaseContext())) {
                    showToast("请检查网络...");
                } else {
                    mBrowserLayout.refresh();
                    toggleHide();
                }
            }
        });
    }


    @Override
    protected void initViewsAndEvents() {
        super.initViewsAndEvents();

/*        mPresenter = new BaseWebPresenterImpl(mContext, this);

        mPresenter.loadingData(TaskConstants.TASK_QUERYOSSWORD, getString(R.string.root_url), Constants.EVENT_DATA,
                ApiConstants.protocol(mContext, mProtocolCode), false);*/

        toolbar_title.setText(mWebTitle);

//        mBrowserLayout.mWebView.getSettings().setAllowFileAccessFromFileURLs(true);

        /**
         * 取WEB页面标题
         */
//		mBrowserLayout.mWebView.setWebChromeClient(new WebChromeClient() {
//
//			@Override
//	        public void onReceivedTitle(WebView view, String title) {
//	            super.onReceivedTitle(view, title);
//	            if(TextUtils.isEmpty(title)){
//	            	toolbar_title.setText(mWebTitle);
//	            }else{
//	            	toolbar_title.setText(title);
//	            }
//	        }
//        });
        /**
         * 取WEB页面标题
         */
    }

    @Override
    public <T> void initializeViews(String task_name, T data) {
        // TODO Auto-generated method stub
/*        if (TextUtils.equals(TaskConstants.TASK_QUERYOSSWORD, task_name)) {
            mUrl = HSJSONTools.getString((String) data, "url");

            mBrowserLayout.loadUrl(mUrl);
        }*/
    }

    @Override
    public <T> void initializeError(String task_name, T data) {
        // TODO Auto-generated method stub

    }

    @Override
    protected boolean isApplyKitKatTranslucency() {
        // TODO Auto-generated method stub
        return false;
    }

}
